﻿using System;
using System.Collections.Generic;
using System.Text;
using IBatisNet.DataAccess.Configuration;
using IBatisNet.DataAccess;
using System.Reflection;
using System.IO;
using log4net;
using log4net.Config;
namespace Ecreate.Data.IFace
{
    public class ServiceInstance:IService
    {
        private IDaoManager _daoManager = null;
        private IHibernateService hibernateservice = null;
        public ServiceInstance()
        {
            DomDaoManagerBuilder builder = new DomDaoManagerBuilder();
            Assembly assembly = Assembly.Load("Ecreate.Model");
            Stream stream = assembly.GetManifestResourceStream("Ecreate.Model.configs.ibatis.dao.config");
            builder.Configure(stream);
            _daoManager = DaoManager.GetInstance("EcreateDao");
        }
        public IDaoManager getDaoManager()
        {
            return _daoManager;
        }
        public Ecreate.Data.IFace.IIBatisService getIBatisService()
        {
            return (Ecreate.Data.IFace.IIBatisService)this._daoManager.GetDao(typeof(Ecreate.Data.IFace.IIBatisService));
        }
        public Ecreate.Data.IFace.IHibernateService getHibernateService()
        {
            if (hibernateservice == null)
            {
                hibernateservice= new Hibernate.HibernateInstance();
            }
            return hibernateservice;
        }
    }
}
